﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace coliseu
{
    public partial class FrmWizardBloco : Form
    {
        private int andar=0;
        private int apto=0;
        private string tipo = "";
        private DataTable dt = new DataTable();
        private bool exclui = false;

        public FrmWizardBloco()
        {
            InitializeComponent();
        }

        private void FrmWizardBloco_Load(object sender, EventArgs e)
        {
           tabControl1.TabPages.Remove(tabPage2);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            andar = Convert.ToInt32(txtAndar.Text);
            apto = Convert.ToInt32(txtNumApto.Text);

            if (rbtn1.Checked)
                tipo = "1";
            if (rbtn2.Checked)
                tipo = "2";
            if (rbtn3.Checked)
                tipo = "3";

            tabControl1.TabPages.Add(tabPage2);
            tabControl1.TabPages.Remove(tabPage1);
         
        }

        private void button4_Click(object sender, EventArgs e)
        {
            tabControl1.TabPages.Add(tabPage1);
            tabControl1.TabPages.Remove(tabPage2);
        }

        private void tabPage2_Enter(object sender, EventArgs e)
        {            
            dt.Columns.Add("Andar");
            dt.Columns.Add("Apto");

            DataRow row;

            int a = 1;
            int ap = 1;

            while (a <= andar)
            {
                while (ap <= apto)
                {
                    row = dt.NewRow();
                    row["Andar"] = a;

                    if(tipo == "1")
                    {
                        row["Apto"] = ap;
                    }

                    if (tipo == "2")
                    {
                        row["Apto"] = a + "" +ap;
                    }

                    if (tipo == "3")
                    {
                        row["Apto"] = a + ap.ToString().PadLeft(2,'0');
                    }

                        dt.Rows.Add(row);

                    ap++;
                }
                ap = 1;
                a++;
            }

            dataGridView1.DataSource = dt;
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            DataRow row = dt.NewRow();

            row["andar"] = txtCriaAndar.Text;
            row["apto"] = txtCriaApto.Text;

            dt.Rows.Add(row);

            dataGridView1.Refresh();
        }

        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            //if (e.RowIndex != -1 )//&& exclui == false)
            //{
            //    txtCriaAndar.Text = dt.Rows[e.RowIndex]["Andar"].ToString();
            //    txtCriaApto.Text = dt.Rows[e.RowIndex]["apto"].ToString();              
            //}
            //exclui = false;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DataRow[] r = dt.Select("andar = " + txtCriaAndar.Text + " and apto = " + txtCriaApto.Text);
            //exclui = true;                 
            dt.Rows.Remove(r[0]);

           
        }

        private void button5_Click(object sender, EventArgs e)
        {

        }
    }
}
